﻿using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace WechatMul
{
    public partial class FormWechatMul : Form
    {
        public FormWechatMul()
        {
            InitializeComponent();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            foreach (var item in Process.GetProcesses())
            {
                if (item.ProcessName == "WeChat")
                {
                    item.Kill();
                    System.Threading.Thread.Sleep(20);
                    break;
                }
            }

            if (string.IsNullOrEmpty(txtPath.Text))
            {
                MessageBox.Show("请先设置微信的可执行文件路径");
                return;
            }
           
            WechatHelper.ExecApplication(txtPath.Text, (int)numCount.Value);
        }

        private void txtPath_Click(object sender, EventArgs e)
        {
            var diag = new OpenFileDialog
            {
                Filter = "exe|*.exe",
                FileName = "Wechat.exe"
            };
            if (diag.ShowDialog() == DialogResult.OK)
            {
                txtPath.Text = diag.FileName;
                System.IO.File.WriteAllText(System.IO.Path.Combine(Application.UserAppDataPath, "cache"), txtPath.Text);
            }
        }

        private void FormWechatMul_Load(object sender, EventArgs e)
        {
            if (System.IO.File.Exists(System.IO.Path.Combine(Application.UserAppDataPath, "cache")))
            {
                txtPath.Text =System.IO.File.ReadAllText(System.IO.Path.Combine(Application.UserAppDataPath, "cache"));
            }
        }
    }
}
